package com.proj.hot.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.proj.hot.GlobalParams;
import com.proj.hot.R;
import com.proj.hot.activity.PayActivity;
import com.proj.hot.utils.DebugUtil;
import com.proj.hot.utils.DownloadFileUtil;

import org.json.JSONObject;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class XWDialogPayTips extends Dialog implements DialogInterface.OnKeyListener{


	Context mContext;
	TextView txt;

	boolean isfinish=false;

	private Handler handler =  new Handler(){
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);

			if(msg.what == 1){

				if(GlobalParams.user_Residualduration<=0){
					handler.removeMessages(1);
				}else{
					txt.setText("包时观看还剩余"+GlobalParams.user_Residualduration/60+"分"+GlobalParams.user_Residualduration%60+"秒,请尽快支付续时");
					handler.sendEmptyMessageDelayed(1,1000);
				}


			}

		}
	};






	public XWDialogPayTips(Context context, String apkurl) {
		super(context, R.style.transDialog);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		this.mContext = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.paytips_view_dialog);
		// 设置标题
		setCanceledOnTouchOutside(false);
		setCancelable(true);

		Window window = getWindow(); //得到对话框
		window.setBackgroundDrawableResource(R.drawable.nothing); //设置对话框背景为透明
		WindowManager.LayoutParams wl = window.getAttributes();
		wl.x = 20; //x小于0左移，大于0右移
		wl.y = 0; //y小于0上移，大于0下移
		wl.gravity = Gravity.BOTTOM|Gravity.RIGHT; //设置重力
		wl.dimAmount = 0f;
		window.setAttributes(wl);

		txt=(TextView) findViewById(R.id.txt);

		setOnKeyListener(this);
		handler.sendEmptyMessageDelayed(1,1000);

	}


	@Override
	public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK){
			isfinish=true;
			handler.removeMessages(0);

		}

		if (keyCode == KeyEvent.KEYCODE_ENTER){
			isfinish=true;
			handler.removeMessages(0);
			dismiss();
			Intent intent = new Intent(mContext, PayActivity.class);
			mContext.startActivity(intent);
		}


		return false;
	}
}
